﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows;

namespace Sinacor.Infra.UI.Controls.SmartClient.Internal
{
    public class GroupByControl : Xceed.Wpf.DataGrid.GroupByControl
    {
        protected override System.Windows.DependencyObject GetContainerForItemOverride()
        {
            return new Internal.GroupByItem();
        }

        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is Internal.GroupByItem;
        }

        //protected override void OnDragEnter(DragEventArgs e)
        //{
        //    base.OnDragEnter(e);
        //}

        //protected override void OnDragLeave(DragEventArgs e)
        //{
        //    base.OnDragLeave(e);
        //}

        //protected override void OnDragOver(DragEventArgs e)
        //{
        //    base.OnDragOver(e);
        //}

        //protected override void OnDrop(DragEventArgs e)
        //{
        //    base.OnDrop(e);
        //}
    }

    public class GroupByItem : Xceed.Wpf.DataGrid.GroupByItem
    {
        #region Construtor
        /// <summary>
        /// Construtor padrão
        /// </summary>
        public GroupByItem()
            : base()
        {
            //this.Loaded += new System.Windows.RoutedEventHandler(GroupByItem_Loaded);
            //this.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(GroupByItem_PreviewMouseLeftButtonUp);
        }
        #endregion

        //#region ExternalColumn
        //SmartClient.Column _externalColumn;
        ///// <summary>
        ///// Coluna exposta
        ///// </summary>
        //public SmartClient.Column ExternalColumn
        //{
        //    get { return _externalColumn; }
        //}
        //#endregion

        //private void GroupByItem_Loaded(object sender, System.Windows.RoutedEventArgs e)
        //{
        //    //// Capturando grid
        //    //SinacorDataGrid grid = (SinacorDataGrid)ControlHelper.FindParent(this, typeof(SinacorDataGrid));
        //    //if (grid == null)
        //    //    throw new InvalidOperationException("Cannot find the parent SinacorDataGrid of GroupByItem");

        //    //// Capturando GroupLevelDescription
        //    //if (!(this.Content is Xceed.Wpf.DataGrid.GroupLevelDescription))
        //    //    throw new InvalidOperationException("The Content of GroupByItem must be a GroupLevelDescription");
        //    //Xceed.Wpf.DataGrid.GroupLevelDescription groupLevelDescription = (Xceed.Wpf.DataGrid.GroupLevelDescription)this.Content;

        //    //// Capturando ExternalColumn
        //    //_externalColumn = ((Internal.Column)grid.InternalDataGrid.Columns[groupLevelDescription.FieldName]).ExternalColumn;

        //    //if (this.ExternalColumn == null)
        //    //    throw new InvalidOperationException("Cannot find the ExternalColumn of GroupByItem");

        //    //// Capturando GroupDescription
        //    //Xceed.Wpf.DataGrid.DataGridGroupDescription groupDescription = null;

        //    //groupDescription = this.ExternalColumn.DataGrid.Items.GroupDescriptions.FirstOrDefault(
        //    //        delegate(GroupDescription value)
        //    //        {
        //    //            if (groupDescription is Xceed.Wpf.DataGrid.DataGridGroupDescription)
        //    //            {
        //    //                if (((Xceed.Wpf.DataGrid.DataGridGroupDescription)value).PropertyName == groupLevelDescription.FieldName)
        //    //                     return true;
        //    //            }
        //    //            return false;
        //    //        }) as Xceed.Wpf.DataGrid.DataGridGroupDescription;

        //    //if (groupDescription == null)
        //    //    throw new InvalidOperationException("Cannot find the GroupDescription of GroupByItem");

        //    //groupDescription.SortComparer = new GroupComparer();
        //}

        //private void GroupByItem_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        //{
        //    //if (this.ExternalColumn == null)
        //    //    throw new InvalidOperationException("Cannot find the ExternalColumn of GroupByItem");

        //    //// Verifica se não está redimensionando e nem arrastando a coluna
        //    //if (this.IsPressed &&
        //    //    !this.IsBeingDragged)
        //    //{
        //    //    this.ExternalColumn.DataGrid.SortColumn(this.ExternalColumn);
        //    //}
        //}
    }
}
